<?php

/*
 * Décrit un utilisateur de l'application
 *
 * @author yahn
 */

class Utilisateur {

    private $login, $password, $nom, $prenom;
    private $lesRoles = array();
    private $lesMails = array();
    private $lesTels = array();
    private $lesEtablissements = array();

    public function __construct($login, $pwd, $nom, $prenom) {
        $this->login = $login;
        $this->prenom = $prenom;
        $this->password = $pwd;
        $this->nom = $nom;
    }

    public function setLogin($login) {
        $this->login = $login;
    }

    public function setPassword($pwd) {
        $this->password = $pwd;
    }

    public function setNom($nom) {
        $this->nom = $nom;
    }

    public function setPrenom($prenom) {
        $this->prenom = $prenom;
    }

    public function getLogin() {
        return $this->login;
    }

    public function getPassword() {
        return $this->password;
    }

    public function getNom() {
        return $this->nom;
    }

    public function getPrenom() {
        return $this->prenom;
    }

    public function addUnRole(Role $role) {
        $this->lesRoles[] = $role;
    }

    public function getLesRoles($num = null) {
        if (isset($num)) {
            return $this->lesRoles[$num];
        } else {
            return $this->lesRoles;
        }
    }

    public function addUnTel(Telephone $tel) {
        $this->lesTels[] = $tel;
    }

    public function addUnMail(Mail $mail) {
        $this->lesMails[] = $mail;
    }

    public function addUnEtablissement(Etablissement $ets) {
        $this->lesEtablissements[] = $ets;
    }

    public function getLesEtablissements($num = null) {
        if (isset($num)) {
            return $this->lesEtablissements[$num];
        } else {
            return $this->lesEtablissements;
        }
    }

    /**
     * Renvoie le <code>Telephone</code> en fonction du type passé en paramètre, <code>null</code> sinon
     * @param type $type type de numero recherché.
     */
    public function getTel($type) {
        if (count($this->lesTels) > 0) {

            if (isset($type)) {
                foreach ($this->lesTels as $tel) {
                    if ($tel->getType() == $type) {
                        return $tel;
                    }
                }
            } else {
                return null;
            }
        }
        return null;
    }

    public function getMail($type) {
        if (count($this->lesMails) > 0) {

            if (isset($type)) {
                foreach ($this->lesMails as $mail) {
                    if ($mail->getType() == $type) {
                        return $mail;
                    }
                }
            } else {
                return null;
            }
        }
        return null;
    }
    
    /**
     * Retourne un tableau avec l'ensemble des mails pour cet <code>Utilisateur</code>.
     * @return type <code>Mail</code>[]
     */
    public function getLesMails() {
        return $this->lesMails;
    }

}

?>
